package com.clps.digital.controller;

import cn.hutool.core.util.ObjUtil;
import com.clps.digital.common.BaseResponse;
import com.clps.digital.common.ErrorCode;
import com.clps.digital.common.ResultUtils;
import com.clps.digital.model.entity.Currency;
import com.clps.digital.model.dto.Currency.TradeCurrency;
import com.clps.digital.model.entity.Property;
import com.clps.digital.model.entity.User;
import com.clps.digital.model.vo.PropertyByCurrency;
import com.clps.digital.service.CurrencyService;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author: 小炎子
 * @Date: 2024/9/2 上午11:08
 * @Description: 法币信息$
 **/
public class CurrencyController {

    private CurrencyService currencyService;

    /*
    * @Author 小炎子
    * @Description 获取所有的法币信息
    * @Date 下午1:56 2024/9/2
    */
    public BaseResponse<List<Currency>> getCurrency() {
        List<Currency> list = currencyService.getCurrency();
        if (ObjUtil.isEmpty(list)){
            return ResultUtils.error(ErrorCode.NOT_FOUND_ERROR);
        }
        return ResultUtils.success(list);
    }

    /*
    * @Author 小炎子
    * @Description 购买法币
    * @Date 下午1:56 2024/9/2
    */
    public BaseResponse<String> buyCurrency(TradeCurrency tradeCurrency) {
        BaseResponse<String> result = currencyService.buyCurrency(tradeCurrency);
        return result;
    }

    /*
    * @Author 小炎子
    * @Description 出售法币
    * @Date 下午3:11 2024/9/2
    */
    public BaseResponse<String> sellCurrency(TradeCurrency tradeCurrency) {
        BaseResponse<String> result= currencyService.sellCurrency(tradeCurrency);
        return result;
    }

    /*
    * @Author 小炎子
    * @Description 获取当前用户的法币资产信息
    * @Date 下午4:51 2024/9/2
    */
    public BaseResponse<List<PropertyByCurrency>> getUserCurrency() {
        return ResultUtils.success(currencyService.getProperty());
    }

    /*
    * @Author 小炎子
    * @Description 根据传入的货币金
    * @Date 下午5:14 2024/9/2
    */
    public BaseResponse<BigDecimal> getCurrencyNumber(BigDecimal bigDecimal, Long id ) {
        BigDecimal bigDecimal1 = currencyService.getCurrencyNumber(bigDecimal,id);
        return ResultUtils.success(bigDecimal1);
    }


}
